layui.use(['form', 'layer'], function () {
    var form = layui.form,
        layer = parent.layer === undefined ? layui.layer : top.layer,
        $ = layui.jquery;

    form.on('select(ProjectInfo)', function (data) {
        //console.log(data.elem); //得到select原始DOM对象
        //console.log(data.value); //得到被选中的值
        //console.log(data.othis); //得到美化后的DOM对象
        var val = data.value.split(":")[0];
        if (val) {
            $(".ServiceChargePrice").val(val);
            form.render();
        }
    });

    form.on("submit(addManager)", function (data) {
        var data = {
            Id: $("#Id").val(),  //主键
            ProjectCode: $(".ServiceChargePrice option:selected").attr("ProjectCode"),// infoArr[0],
            ProjectUnit: $(".ServiceChargePrice option:selected").attr("ProjectUnit"), //infoArr[2],  
            ProjectPrice: $(".ProjectPrice").val(),
            AgentProjectPrice: $(".AgentProjectPrice").val(),
            ProjectName: $(".ServiceChargePrice option:selected").attr("ProjectName"), // infoArr[1], 
            ProjectManagerId: $(".ProjectManagerId").val()
        };
        //console.log(data)
        //获取防伪标记
        $.ajax({
            type: 'POST',
            url: '/TradeCommission/AddOrModify/',
            data: data,
            dataType: "json",
            headers: {
                "X-CSRF-TOKEN-yilezhu": $("input[name='AntiforgeryKey_yilezhu']").val()
            },
            success: function (res) {//res为相应体,function为回调函数
                if (res.ResultCode === 200) {
                    var alertIndex = layer.alert(res.ResultMsg, { icon: 1 }, function () {
                        layer.closeAll("iframe");
                        //刷新父页面
                        parent.location.reload();
                        top.layer.close(alertIndex);
                    });
                }
                else {
                    layer.alert(res.ResultMsg, { icon: 5 });
                }
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                layer.alert('操作失败！！！' + XMLHttpRequest.status + "|" + XMLHttpRequest.readyState + "|" + textStatus, { icon: 5 });
            }
        });
        return false;
    });
    form.verify({
        totalservice: function (value, item) { //value：表单的值、item：表单的DOM对象
            var num1 = parseFloat($(".ProjectPrice").val());
            var num2 = parseFloat(value);
            var num = num1 + num2;
            var total = parseFloat($(".ServiceChargePrice option:selected").attr("price"));
            if (total != num) {
                return '“返佣 = 手续费 - 成本”';
            }
        }

        ////我们既支持上述函数式的方式，也支持下述数组的形式
        ////数组的两个值分别代表：[正则匹配、匹配不符时的提示文字]
        //, pass: [
        //    /^[\S]{6,12}$/
        //    , '密码必须6到12位，且不能出现空格'
        //]
    });   
    

});